<template>
  <el-dialog title="审核评论" :visible.sync="visible" v-if="visible">
    <el-form ref="formRef" :model="formData" label-postion="right" label-width="100px">
      <el-form-item label="文章标题">
        <el-input v-model="formData.article.title" disabled></el-input>
      </el-form-item>
      <el-form-item label="评论人">
        <el-input v-model="formData.name" disabled></el-input>
      </el-form-item>
      <el-form-item label="评论内容">
        <el-input type="textarea" :row="5" v-model="formData.content" disabled></el-input>
      </el-form-item>
      <el-form-item label="评论状态">
        <el-select v-model="formData.commentStatus" disabled>
          <el-option :value="1" label="待审核"/>
          <el-option :value="2" label="已通过"/>
          <el-option :value="3" label="已拒绝"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="exam(2)">通过</el-button>
        <el-button type="danger" @click="exam(3)">拒绝</el-button>
        <el-button type="warning" @click="visible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
const formData = {
  commentId: '',
  name: '',
  content: '',
  commentStatus: '',
  article: {
    title: ''
  }
}
export default {
  name: 'CommentExam',
  data () {
    return {
      formData: {
        ...formData
      },
      visible: false
    }
  },
  methods: {
    init (commentId) {
      this.visible = true
      this.$http.get(`admin/comment/info/${commentId}`).then(data => {
        this.formData = { ...data.data }
      })
    },
    exam (commentStatus) {
      this.$http.post('admin/comment/update', {
        commentId: this.formData.commentId,
        commentStatus
      }).then(() => {
        this.$alert('审核完成', { type: 'success' }).then(() => {
          this.visible = false
          this.$emit('closeDialog')
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
